#!/bin/bash
#set  -x
if [ $# -eq 1 ]; then
    day="$1"
else
    day=`date +%Y%m%d --date '-1 day'`
fi
#baseurl="http://10.5.12.243:50075/streamFile/dsap/resultdata/ec_data/EC_Post_Detail_Job/${day}"
downLoadFiles(){
	#reqUrl='http://dsap2.web.58dns.org/dsap-agent/?targetserver=db-cdh-216&targetport=50075&targetpage=browseDirectory&targetprefix=jsp&dir='$baseHdfsPath'&namenodeInfoPort=50070&nnaddr=10.5.12.196:9000'
	reqUrl='http://dsap2.web.58dns.org/dsap-agent/?targetserver=db-cdh-15-229&targetport=50075&targetpage=browseDirectory&targetprefix=jsp&dir='$baseHdfsPath'&namenodeInfoPort=50070&nnaddr=10.9.14.196:9000'	
	nameList=`wget "$reqUrl" -O- 2>/dev/null|grep -Po '(?<=:9000">)[^/]*?(?=</a></B><br></td>)'|sed '/^_/d'`
	while read name
	do
		downFileFullName=$baseHdfsPath/$name
		tmpUrl="http://10.9.15.19:50075/streamFile$downFileFullName?nnaddr=10.9.14.196:9000"		
		wget "$tmpUrl"  -O $name
	done< <(echo "$nameList")	
} 
baseHdfsPath="/dsap/resultdata/ec_data/EC_Post_Detail_Job/${day}"
downLoadFiles "$baseHdfsPath"
python /work/opt/fourthinfo/data/formatMysqlRow.py .  ${day} 1>logs/stdout_${day}.log 2>logs/stderr_${day}.log &